package com.CommunityHub.kiana.controller;

import com.CommunityHub.kiana.po.User;
import com.CommunityHub.kiana.service.MemberService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "MemberHomeServlet", value = "/MemberHomeServlet")
public class MemberHomeServlet extends HttpServlet {
    MemberService memberService = new MemberService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        HttpSession session = request.getSession(false);
        User user = (User) session.getAttribute("user");
        int memberId = user.getId();

        MemberService.CompleteMemberInfo info = null;
        try {
            info = memberService.getCompleteMemberInfo(memberId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        session.setAttribute("memberInfo", info);
        response.sendRedirect("memberHome.jsp");
    }
}
